package dialogs;

import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import controllers.AbstractController;
import controllers.CustomerSearchController;

public class SearchItemDialog extends AbstractGeneralPurposeDialog 
{
	CustomerSearchController controller;

	public SearchItemDialog(JFrame parent, String title, String table, String[] labels, AbstractController c)
	{
		super(parent, title, table, labels, c);
		controller= (CustomerSearchController) c;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) 
	{
		// TODO Auto-generated method stub
		if (e.getActionCommand().equals("OK"))
		{
			int retCode = controller.performSearch(text_fields.get(0),text_fields.get(1),text_fields.get(2));
			if(retCode == VALIDATIONERROR)
				JOptionPane.showMessageDialog(this, "Please fill in at least one of the fields", "Error",
						JOptionPane.ERROR_MESSAGE);
			else if(retCode == OPERATIONFAILED)
				JOptionPane.showMessageDialog(this, "No results OR Search inputs are invalid", "Error",
						JOptionPane.ERROR_MESSAGE);
			else 
				dispose();
		}
			
	}

}
